{include file='public/meta' }
<title>用户配置 - 木鱼内容管理系统</title>
<style type="text/css">
    .wrap {
        width: 1200px;
        margin: 20px auto;
    }

    .form1 {
        display: flex;
    }

    .addBtn {
        margin-left: 40px;
    }
    .layui-badge {
        height: 28px;
        line-height: 28px;
    }
    .dispalyd{
        display: none;
    }
    .inputSize {
        width:100px;
    }
    .rightDiv {
        margin-left:56%;
        width:40%;
        height:340px;
    }
</style>
</head>
<body>
<div class="wrap">
    <!-- 定义头衔 -->
    <div class="layui-card" style="float:left;width:55%">
        <div class="layui-card-header">定义头衔(<span style="color:red;">单击头衔编辑,双击删除头衔</span>)</div>
        <div class="layui-card-body">
            <div>
                <form class="layui-form" action="">
                    <input type="hidden" name="id" id="titleid" value="" />
                    <div class="form1">
                        <div class="layui-form-item">
                            <label class="layui-form-label">头衔名称</label>
                            <div class="layui-input-block">
                                <input type="text" id="titletitle" name="name" value="" required lay-verify="required"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所需经验</label>
                            <div class="layui-input-block">
                                <input type="n" name="suffer" id="titlesuffer" value="" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <button type="submit" lay-submit lay-filter="addtitle" class="layui-btn addBtn">添加</button>
                        <button type="submit" lay-submit lay-filter="edittitle" id="titletoedit" class="layui-btn addBtn dispalyd">修改</button>
                    </div>
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-panel">
                                <div style="padding: 10px;">
                                    {foreach $titles as $tit}
                                    <span data-titleid="{$tit.id}" data-titles="{$tit.name}" data-suffer="{$tit.suffer}" ondblclick="ondblclicks(this,'title')" onclick="chlicks(this,'title')" class="layui-badge layui-bg-green">{$tit.name}</span>
                                    {/foreach}
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- 定义等级 -->
    <div class="layui-card" style="float:left;width:55%">
        <div class="layui-card-header">定义等级(<span style="color:red;">单击等级编辑,双击删除等级</span>)</div>
        <div class="layui-card-body">
            <div>
                <form class="layui-form" action="">
                    <input type="hidden" name="id" id="gradeid" value="" />
                    <div class="form1">
                        <div class="layui-form-item">
                            <label class="layui-form-label">添加等级</label>
                            <div class="layui-input-block">
                                <input type="text" name="grade" value="" id="gradetitle" required lay-verify="required"
                                       autocomplete="off" class="layui-input xftz">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所需经验</label>
                            <div class="layui-input-block">
                                <input type="text" name="suffer" value="" id="gradesuffer" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <button type="submit" lay-submit lay-filter="addgrade" class="layui-btn addBtn">添加</button>
                        <button type="submit" lay-submit lay-filter="editgrade" id="gradetoedit" class="layui-btn addBtn dispalyd">修改</button>
                    </div>
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-md12">
                            <div class="layui-panel">
                                <div style="padding: 10px;">
                                    {foreach $grades as $gra}
                                    <span data-titleid="{$gra.id}" data-titles="{$gra.grade}" data-suffer="{$gra.suffer}" ondblclick="ondblclicks(this,'grade')" onclick="chlicks(this,'grade')" class="layui-badge layui-bg-green dblclicks">{$gra.grade}</span>
                                    {/foreach}
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- 经验阀设置 -->
    <div class="layui-card rightDiv">
        <div class="layui-card-header">经验阀设置(<span style="color:red;">事件所得经验配置</span>)</div>
        <div class="layui-card-body">
            <div>
                <form class="layui-form" action="">
                    <div class="form1">
                        <input type="hidden" name="sufferid" value="{$suffer.sufferid}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">投稿</label>
                            <div class="layui-input-block">
                                <input type="text" name="tgsuffer" value="{$suffer.tgsuffer}" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input inputSize">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">点赞</label>
                            <div class="layui-input-block">
                                <input type="text" name="lisuffer" value="{$suffer.lisuffer}" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input inputSize">
                            </div>
                        </div>
                    </div>
                    <div class="form1">
                        <div class="layui-form-item">
                            <label class="layui-form-label">评论</label>
                            <div class="layui-input-block">
                                <input type="text" name="cosuffer" value="{$suffer.cosuffer}" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input inputSize">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">收藏</label>
                            <div class="layui-input-block">
                                <input type="text" name="fasuffer" value="{$suffer.fasuffer}" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input inputSize">
                            </div>
                        </div>
                    </div>
                    <div class="form1">
                        <div class="layui-form-item">
                            <label class="layui-form-label">签到</label>
                            <div class="layui-input-block">
                                <input type="text" name="signsuffer" value="{$suffer.signsuffer}" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input inputSize">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">注册</label>
                            <div class="layui-input-block">
                                <input type="text" name="regsuffer" value="{$suffer.regsuffer}" required lay-verify="required|checknum"
                                       autocomplete="off" class="layui-input inputSize">
                            </div>
                        </div>
                    </div>
                    <div class="form1">
                        <button type="submit" lay-submit lay-filter="suffer" class="layui-btn addBtn" style="margin-left:40%;">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{include file='public/footer' }
<script>
    layui.config({
        base: '__ADMINST__layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form','layer'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form ;

        form.on('submit(suffer)', function(data){
            for(var s in data.field){
                if(s !== 'sufferid'){
                    if(!/^([0]|[1-9][0-9]*)$/.test(data.field[s])){
                        layer.msg(s+"存在错误值", {time: 2000});
                        return false;
                    }
                }
            }
            ajaxway(data.field,"{:url('admin/Member/settingssuffer')}");
            return false;
        });

        form.on('submit(edittitle)', function(data){
            var Data = data.field;
            Data['type'] = 'title';
            for(var t in Data){
                if(t == 'suffer'){
                    if(!/^([0]|[1-9][0-9]*)$/.test(Data[t])){
                        layer.msg(t+"存在错误值", {time: 2000});
                        return false;
                    }
                }
            }
            ajaxway(Data,"{:url('admin/Member/edittitgra')}");
            return false;
        });

        form.on('submit(addtitle)', function(data){
            var Data = data.field;
            Data['type'] = 'title';
            for(var t in Data){
                if(t == 'suffer'){
                    if(!/^([0]|[1-9][0-9]*)$/.test(Data[t])){
                        layer.msg(t+"存在错误值", {time: 2000});
                        return false;
                    }
                }
            }
            ajaxway(Data,"{:url('admin/Member/addtitgra')}");
            return false;
        });
        form.on('submit(editgrade)', function(data){
            var Data = data.field;
            Data['type'] = 'grade';
            for(var t in Data){
                if(t == 'suffer'){
                    if(!/^([0]|[1-9][0-9]*)$/.test(Data[t])){
                        layer.msg(t+"存在错误值", {time: 2000});
                        return false;
                    }
                }
            }
            ajaxway(Data,"{:url('admin/Member/edittitgra')}");
            return false;
        });
        form.on('submit(addgrade)', function(data){
            var Data = data.field;
            Data['type'] = 'grade';
            for(var t in Data){
                if(t == 'suffer'){
                    if(!/^([0]|[1-9][0-9]*)$/.test(Data[t])){
                        layer.msg(t+"存在错误值", {time: 2000});
                        return false;
                    }
                }
            }
            ajaxway(Data,"{:url('admin/Member/addtitgra')}");
            return false;
        });
        form.verify({
            checknum:function(value){
                if(!/^([0]|[1-9][0-9]*)$/.test(value)){
                    return "只能输入正整数";
                }
            }
        });
    })
    var clicktime = null;
    //头衔等级双击事件处理
    function ondblclicks(data,type){
        if (clicktime) {
            window.clearTimeout(clicktime);
            clicktime = null;
        }
        $("#"+type+"title").val("");
        $("#"+type+"suffer").val("");
        $("#"+type+"id").val("");
        $("#"+type+"toedit").addClass("dispalyd");
        var names;
        var Data;
        if(type === 'grade'){
            names = "等级";
        }else if(type === 'title'){
            names = "头衔";
        }
        var ids = data.getAttribute("data-titleid");
        layer.msg('确认删除'+names+'['+data.getAttribute("data-titles")+']？', {
            time: 5000, //5s后自动关闭
            shade: 0.3,
            btn: ['确认', '取消'],
            yes: function() {
                Data = {id:ids,type:type};
                ajaxway(Data,"{:url('Member/deletetitgr')}");
                return false;
            }
        });
    }
    //头衔等级单击处理
    function chlicks(data,info){
        if (clicktime) {
            window.clearTimeout(clicktime);
            clicktime = null;
        }
        clicktime = window.setTimeout(function() {
            var id = data.getAttribute("data-titleid");
            var title = data.getAttribute("data-titles");
            var suffer = data.getAttribute("data-suffer");
            $("#"+info+"title").val(title);
            $("#"+info+"suffer").val(suffer);
            $("#"+info+"id").val(id);
            $("#"+info+"toedit").removeClass("dispalyd");//显示修改按钮
        }, 250);
    }
    function ajaxway(Data,url){
        $.ajax({
            type: 'POST',
            data: Data,
            url: url,
            dataType: "json",
            beforeSend: function() {
                index = layer.load();
            },
            success: function(data) {
                if(data.code === 1){
                    layer.msg(data.msg, {time: 2000}, function() {
                        location.reload();
                    });
                }else{
                    layer.msg(data.msg, {time: 2000});
                }
            },
            complete: function() {
                layer.close(index);
            }
        });
    }
</script>
</body>
</html>